<?php
include_once "xAP-functions/webincludes.php";


$extradata["Category"]=$_GET["id"];
$now=date("Y-m-d H:i:s");

if(substr($extradata["Category"],0,4)=="Cat-"){
	// just one source
	$sql="select a.Alias,s.StoryID,s.DateStamp,s.Title,s.URL,s.Body,s.TagList,a.SourceID,a.Category from 
			xAP_News_Story as s  INNER JOIN  xAP_News_Source as a ON
			a.SourceID=s.SourceID
			where a.Category='".dbesc(substr($extradata["Category"],4))."' 
			
			order by s.datestamp DESC limit 10";
	$results=dbquery($sql);
	$title=$results[0]["Category"]." News";
}
elseif(substr($extradata["Category"],0,4)=="SRC-"){
	// just one source
	$sql="select a.Alias,s.StoryID,s.DateStamp,s.Title,s.URL,s.Body,s.TagList,a.SourceID from 
			xAP_News_Story as s  INNER JOIN  xAP_News_Source as a ON
			a.SourceID=s.SourceID 
			where s.SourceID=".intval(substr($extradata["Category"],4))."
			order by s.datestamp DESC limit 10";
	$results=dbquery($sql);
	$title=$results[0]["Alias"]." News";
}
else
{
	// all sources
	$sql="select a.Alias,s.StoryID,s.DateStamp,s.Title,s.URL,s.Body,s.TagList,a.SourceID from 
			xAP_News_Story as s  INNER JOIN  xAP_News_Source as a ON
			a.SourceID=s.SourceID order by s.datestamp DESC limit 10";
	$results=dbquery($sql);
	$title="Latest News";
}


//display
$body= "<Table class='widget'>";
foreach($results as $row){	
	$body.= "<tr>
	<TD class='normalsmalltext'>
	<a href='/".$config["modulefolder"]."/index.php?id=".$row["SourceID"]."' class='blacktext'>
	".substr($row["Title"],0,60)."
	</a></td>
	</tr>
	";

}
$body.= "</table>";
echo $body;
?>